﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Application
open System.Security;
open System.Net
open System

// =======================================================
// Add likes-rating to library
// =======================================================

let web = Client.Context.Web

Client.Load web

let list = web.Lists.GetByTitle("Documents")
Client.Context.Load(list)
Client.ExecuteQuery()

let spFolder = list.RootFolder
Client.Context.Load(spFolder)
Client.ExecuteQuery()
spFolder.Properties.["Ratings_VotingExperience"] <- "Likes"
spFolder.Update()
Client.ExecuteQuery()

let LikesCount = web.Fields.GetByInternalNameOrTitle("LikesCount")
Client.Load LikesCount
list.Fields.Add(LikesCount)

let LikedBy = web.Fields.GetByInternalNameOrTitle("LikedBy")
Client.Load LikedBy
list.Fields.Add(LikedBy)
list.Update()
Client.ExecuteQuery()

